home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Graphics / RTGmaster / demos / flame / flame.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-26  |  7.3 KB  |  306 lines

  1. /*
  2.         Flame
  3.  
  4.         A demo of rtg.library
  5.  
  6.         Written by Thomas & Hans-Jörg Frieden
  7.                    Schlossstr. 176
  8.                    54293 Trier
  9.                    tfrieden@fax.uni-trier.de
  10.                    hfrieden@fix.uni-trier.de
  11.  
  12. */
  13. //* "Includes"
  14. #include <stdlib.h>
  15. #include <proto/utility.h>
  16. #include <proto/exec.h>
  17. #include <clib/rtgmaster_protos.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/utility_protos.h>
  20. #include <pragmas/rtgmaster_pragmas.h>
  21. #include <pragmas/exec_pragmas.h>
  22. #include <pragmas/utility_pragmas.h>
  23. #include <exec/memory.h>
  24. #include <utility/tagitem.h>
  25. #include <rtgmaster/rtgmaster.h>
  26. #include <rtgmaster/rtgsublibs.h>
  27. #include <rtgmaster/rtgc2p.h>
  28. #include <proto/rtgmaster.h>
  29. #include "timer.h"
  30. #include <string.h>
  31. #include <stdio.h>
  32. //*
  33. //* "Defines"
  34. #define XSIZE 80
  35. #define YSIZE 65
  36. #define YSCRN 60
  37. #define MSIZE (XSIZE*YSIZE)
  38. #define DECAY 3
  39. #define CBUF    76800
  40. //*
  41. //* "Pragmas"
  42. extern void __asm CopyFrame(register __a0 UBYTE *adr, 
  43.                             register __d0 ULONG size);
  44. extern void __asm CopyFrame2(register __a0 UBYTE *adr, 
  45.                              register __d0 ULONG aize);
  46. extern void __asm DrawMeter(register __a0 APTR buf, 
  47.                             register __d0 ULONG fps);
  48.  
  49. UBYTE MouseButton(void);
  50. //*
  51. //* "Globals"
  52. struct RtgScreen *RtgScreen;
  53. struct ScreenReq *sr;
  54. struct RTGMasterBase *RTGMasterBase;
  55. struct Library *UtilityBase;
  56. struct TagItem rtag[] = {
  57.     smr_MinWidth,       320,
  58.     smr_MinHeight,      200,
  59.     smr_MaxWidth,       640,
  60.     smr_MaxHeight,      512,
  61.     smr_ChunkySupport,  512,
  62.     smr_PlanarSupport,  -1,
  63.     TAG_DONE,           NULL
  64. };
  65.  
  66. struct TagItem gtag[] = {
  67.     grd_BytesPerRow,    0,
  68.     grd_Width,          0,
  69.     grd_Height,         0,
  70.     grd_Depth,          0,
  71.     grd_PixelLayout,    0,
  72.     grd_ColorSpace,     0,
  73.     grd_PlaneSize,      0,
  74.     TAG_DONE,           0
  75. };
  76.  
  77. struct TagItem tacks[] = {
  78.     TAG_DONE,0
  79. };
  80.  
  81. UBYTE *sc1;
  82. UBYTE scrn[MSIZE];
  83. ULONG cmap[800];
  84. UBYTE blah;
  85. BOOL Planar;
  86. UBYTE *cbuf=NULL;
  87. ULONG width;
  88. UBYTE *sadr;
  89. ULONG num,avg;
  90. ULONG c2psignal;
  91. //*
  92. //* "NewFrame"
  93. void NewFrame(void) {
  94.     int i,x;
  95.     UBYTE *a;
  96.  
  97.     extern void GenFrame(void);
  98.  
  99.     a=&scrn[MSIZE-1]; i=XSIZE;
  100.  
  101.     while (i>0) {
  102.         x=rand();
  103.         if (x>RAND_MAX/2) *a=255;
  104.         else *a=0;
  105.         i--; a--;
  106.     }
  107.  
  108.     i=MSIZE-XSIZE-1;
  109.     a=scrn;
  110.  
  111.     GenFrame();
  112. }
  113. //*
  114. //* "DrawFrame"
  115. void DrawFrame(struct RtgScreen *s, ULONG size, ULONG ticks) {
  116.     if (blah==0) CopyFrame(cbuf, size);
  117.     else CopyFrame2(cbuf,size);
  118.     DrawMeter(cbuf, ticks);
  119.     CopyRtgPixelArray(RtgScreen,sadr,cbuf,0,0,320,200,0,0);
  120. }
  121. //*
  122. //* "DrawFrameP"
  123. void DrawFrameP(struct RtgScreen *s, ULONG size, ULONG ticks) {
  124.     UBYTE *adr;
  125.  
  126.     adr=cbuf;                               // Draw into chunky buffer first
  127.     if (blah==0) CopyFrame(adr, 320);
  128.     else CopyFrame2(adr,320);
  129.     DrawMeter(adr, ticks);
  130.     adr = sadr;
  131.     CallRtgC2P(s,adr,cbuf,c2psignal,0,0,320,200,c2p_Selected);
  132.     Wait(1<<c2psignal);
  133. }
  134. //*
  135. //* "fail"
  136. void fail(void) {
  137.     if (RtgScreen) CloseRtgScreen(RtgScreen);
  138.     if (RTGMasterBase) CloseLibrary((struct Library *)RTGMasterBase);
  139.     if (UtilityBase) CloseLibrary(UtilityBase);
  140.     if (cbuf) FreeMem(cbuf, CBUF);
  141.     exit(0L);
  142. }
  143. //*
  144. //* "main"
  145. void main(int argc, char **argv) {
  146.    /*
  147.     * Since this is a demo, I don't check anything at all
  148.     * and simply assume that every open went ok... 8-)
  149.     */
  150.     int i, x;
  151.     struct TagItem *tag;
  152.     UBYTE rr, rg, rb;
  153.     ULONG size;
  154.     ULONG ticks=0, max=0, min=300;
  155.  
  156.     if (argc>1 && stricmp(argv[1],"small")==0) blah=1; else blah=0;
  157.  
  158.     if (InitTimer()==FALSE) {
  159.         printf("Unable to open timer device\n");
  160.         fail();
  161.     }
  162.  
  163.     RTGMasterBase = (struct RTGMasterBase *)OpenLibrary((STRPTR)"rtgmaster.library", 0);
  164.     UtilityBase = OpenLibrary((STRPTR)"utility.library", 37L);
  165.     c2psignal=AllocSignal(-1);
  166.     sr = RtgScreenModeReq(rtag);
  167.  
  168.     if (sr==NULL) fail();
  169.     if (c2psignal==-1) fail();
  170.     RtgScreen = OpenRtgScreen(sr, tacks);
  171.  
  172.     GetRtgScreenData(RtgScreen, gtag);
  173.  
  174.     tag=FindTagItem(grd_BytesPerRow, gtag);
  175.     size = tag->ti_Data;
  176.  
  177.     tag=FindTagItem(grd_Width, gtag);
  178.     width = tag->ti_Data;
  179.  
  180.     tag=FindTagItem(grd_PixelLayout, gtag);
  181.     if (tag->ti_Data != grd_PLANAR && tag->ti_Data != grd_CHUNKY) {
  182.         printf("Screenmode not supported\n");
  183.         fail();
  184.     }
  185.  
  186.     if (tag->ti_Data == grd_PLANAR) Planar = TRUE;
  187.     else Planar = FALSE;
  188.  
  189.     printf("Screen is %ld x %ld x %ld\n", gtag[1].ti_Data, gtag[2].ti_Data, gtag[3].ti_Data);
  190.     printf("It has %ld bytes per row", size);
  191.     if (size>gtag[1].ti_Data) {
  192.         printf(", which means that the screen is wider than what you see\n");
  193.     } else printf("\n");
  194.  
  195.         cbuf = AllocMem(CBUF, MEMF_CLEAR|MEMF_FAST);
  196.         if (cbuf==NULL) {
  197.             cbuf=AllocMem(CBUF, MEMF_CLEAR);
  198.             if (cbuf==NULL) {
  199.                 printf("Out of memory *SIGH*\n");
  200.                 fail();
  201.             }
  202.         }
  203.  
  204. if (gtag[3].ti_Data==8)
  205. {
  206.     cmap[0] = 256 * 65536;
  207.     rr = 0;
  208.     rg = 0;
  209.     rb = 0;
  210.     x = 1;
  211.     for (i = 0; i < 64; i++) {
  212.         cmap[x++] = rr * 0x1111111;
  213.         cmap[x++] = rg * 0x1111111;
  214.         cmap[x++] = rb * 0x1111111;
  215.         rr += 3;
  216.     }
  217.     for (i = 0; i < 127; i++) {
  218.         cmap[x++] = rr * 0x1111111;
  219.         cmap[x++] = rg * 0x1111111;
  220.         cmap[x++] = rb * 0x1111111;
  221.         rg += 3;
  222.     }
  223.     for (i = 0; i < 60; i++) {
  224.         cmap[x++] = rr * 0x1111111;
  225.         cmap[x++] = rg * 0x1111111;
  226.         cmap[x++] = rb * 0x1111111;
  227.         rb += 3;
  228.     }
  229.     for (i = 0; i < 4; i++) {
  230.         cmap[x++]=0xFFFFFFFF;
  231.         cmap[x++]=0xFFFFFFFF;
  232.         cmap[x++]=0xFFFFFFFF;
  233.     }
  234.     cmap[x++]=0;
  235. }
  236. else
  237. {
  238.    cmap[0] = 64 * 65536;
  239.     rr = 0;
  240.     rg = 0;
  241.     rb = 0;
  242.     x = 1;
  243.     for (i = 0; i < 16; i++) {
  244.         cmap[x++] = rr * 0x1111111;
  245.         cmap[x++] = rg * 0x1111111;
  246.         cmap[x++] = rb * 0x1111111;
  247.         rr += 12;
  248.     }
  249.     for (i = 0; i < 31; i++) {
  250.         cmap[x++] = rr * 0x1111111;
  251.         cmap[x++] = rg * 0x1111111;
  252.         cmap[x++] = rb * 0x1111111;
  253.         rg += 12;
  254.     }
  255.     for (i = 0; i < 12; i++) {
  256.         cmap[x++] = rr * 0x1111111;
  257.         cmap[x++] = rg * 0x1111111;
  258.         cmap[x++] = rb * 0x1111111;
  259.         rb += 12;
  260.     }
  261.     for (i = 0; i < 4; i++) {
  262.         cmap[x++]=0xFFFFFFFF;
  263.         cmap[x++]=0xFFFFFFFF;
  264.         cmap[x++]=0xFFFFFFFF;
  265.     }
  266.     cmap[x++]=0;
  267. }
  268.     LockRtgScreen(RtgScreen);
  269.     LoadRGBRtg(RtgScreen, (APTR) cmap);
  270.     UnlockRtgScreen(RtgScreen);
  271.  
  272.     if (RtgScreen) {
  273.         LockRtgScreen(RtgScreen);
  274.         sadr = (UBYTE *)GetBufAdr(RtgScreen,0);
  275.  
  276.         Forbid();
  277.         num=0;
  278.         while(MouseButton()==0) {
  279.             StartClock();
  280.             NewFrame();
  281.             if (Planar==FALSE) DrawFrame(RtgScreen, size, ticks);
  282.             else DrawFrameP(RtgScreen, size, ticks);
  283.             ticks=StopClock();
  284.             num++;
  285.             avg+=ticks;
  286.             if (max<ticks) max=ticks;
  287.             if (min>ticks) min=ticks;
  288.         }
  289.         Permit();
  290.         UnlockRtgScreen(RtgScreen);
  291.         CloseRtgScreen(RtgScreen);
  292.     }
  293.     if (max==0) max=1;
  294.     if (min==0) min=1;
  295.     printf("Min Frame rate: %ld\n", max);
  296.     printf("Max Frame rate: %ld\n", min);
  297.     printf("Avg Frame rate: %ld\n", avg/num);
  298.     CloseTimer();
  299.     FreeSignal(c2psignal);
  300.     FreeMem(cbuf,CBUF);
  301.     CloseLibrary((struct Library *)RTGMasterBase);
  302.     CloseLibrary(UtilityBase);
  303. }
  304. //*
  305.  
  306.